Jump to content

- Functions

- # LogCallIntoTextFile()

  Followers 0

  Lua → VBScript

  This function logs some details into a given log (text) file.

  Please see the Introduction chapter for some usage instructions.

  Please note: the Lua Beta Testing versions of SwyxWare (13.1x) do not limit any file access. In the final release version file access will only be permitted in the SwyxWare CPE (customer premise equipment) version. Within the cloud versions (SDC and SwyxON) file access will not be permitted.

      local LogFormat = '"#NUMBER#","#NAME#","#TIMESTAMP#"'

      ------------------------------------------------------------------
      -- Function LogCallIntoTextFile
      --
      -- Logs details of the current call into a text file.
      -- Line format: "Number","Name","Timestamp"
      --
      -- Parameter:
      --   sFileName   name of logfile (incl. path)
      --
      -- Return:
      --   boolean     true - log created, false - error creating log
      ------------------------------------------------------------------
      function LogCallIntoTextFile ( sFileName )

          PBXScript.OutputTrace ("-----------> LogCallIntoTextFile ( " .. sFileName .. " )")

          local bReturn = false
          local sLine   = ""

          local oFile = io.open(sFileName, "a") -- append mode
          if oFile then
              -- create log line
              sLine = LogFormat
              sLine = StringReplace(sLine, "#NUMBER#",    PBXCall.CallingPartyNumber())
              sLine = StringReplace(sLine, "#NAME#",      PBXCall.CallingPartyName())
              sLine = StringReplace(sLine, "#TIMESTAMP#", PBXUser.Now())
              PBXScript.OutputTrace ("sLine = " .. sLine)
              -- write (append) log data to file
              oFile:write(sLine)
              oFile:close()
              bReturn = true
          else
              PBXScript.OutputTrace ("Error opening log file!")
          end

          PBXScript.OutputTrace ("bReturn = " .. tostring(bReturn))
          PBXScript.OutputTrace ("<----------- LogCallIntoTextFile")

          return bReturn
      end

  This function makes use of the Server Script API functions PBXCall.CallingPartyNumber(), PBXCall.CallingPartyName() and PBXUser.Now() for the call details and PBXScript.OutputTrace to write trace information into the SwyxServer trace file. It also uses the GSE build-in helper function StringReplace() to format the log data.

  You need to make sure, that the file can be accessed from the call routing script. For this it is necessary, that the Windows users the Swyx Server service is running under (usually SwyxServiceAccount) has at least read privileges on the file.

  Please note, that you have to escape backslashes in the sFileName parameter. So instead of "C:\Files\logfile.txt" you have to pass "C:\\Files\\logfile.txt".

  By Tom Wellige

  - June 9, 2022
  Share
  Share
  Followers 0
  Previous Page LaunchHTTPRequest()
  Next Page NumberOfLoggedInUsersInGroup

## Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.